package com.easywan.vo;

public class ToolsIdCard {
	//public static final String HLJ_QQHES_LSQ = "230202";
	
	
	
	public static String randomIdCard(){
		String idCode = randomCode()+randomDateString() + randomGACoed() + randomGender();
		return idCode+getVifcode(idCode);
	}
	/**
	 * 获取最后一位校检码
	 * @param idCode
	 * @return
	 * 1.1x7 2x9 3x10 4x5 5x8 6x4 7x2 8x1 9x6 10x3 11x7 12 x9 13x10 14x5 15x8 16x4 17x2
	 * 0-1  1-0  2-X 3-9 4-8 5-7 6-6 7-5 8-4 9-3 10-2 
	 */
	private static String getVifcode(String idCode) {
		int sum = 0;
		sum += Integer.valueOf(idCode.charAt(0)) * 7;
		sum += Integer.valueOf(idCode.charAt(1)) * 9;
		sum += Integer.valueOf(idCode.charAt(2)) * 10;
		sum += Integer.valueOf(idCode.charAt(3)) * 5;
		sum += Integer.valueOf(idCode.charAt(4)) * 8;
		sum += Integer.valueOf(idCode.charAt(5)) * 4;
		sum += Integer.valueOf(idCode.charAt(6)) * 2;
		sum += Integer.valueOf(idCode.charAt(7)) * 1;
		sum += Integer.valueOf(idCode.charAt(8)) * 6;
		sum += Integer.valueOf(idCode.charAt(9)) * 3;
		sum += Integer.valueOf(idCode.charAt(10)) * 7;
		sum += Integer.valueOf(idCode.charAt(11)) * 9;
		sum += Integer.valueOf(idCode.charAt(12)) * 10;
		sum += Integer.valueOf(idCode.charAt(13)) * 5;
		sum += Integer.valueOf(idCode.charAt(14)) * 8;
		sum += Integer.valueOf(idCode.charAt(15)) * 4;
		sum += Integer.valueOf(idCode.charAt(16)) * 2;
		
		int code = sum % 11;
		switch(code){
		case 0: return "1";
		case 1: return "0";
		case 2: return "X";
		case 3: return "9";
		case 4: return "8";
		case 5: return "7";
		case 6: return "6";
		case 7:return "5";
		case 8: return "4";
		case 9:return "3";
		case 10:return "2";
		}
		return null;
	}
	private static String randomCode(){
		String[] code = new String[]{"230202"};
		return code[((int)(Math.random()*100)) % code.length];
	}
	private static String randomDateString(){
		int year = 1970;
		year += ((int)(Math.random() * 100)) % 47;
		int month = ((int)(Math.random() * 100)) %12 +1;
		int day = ((int)(Math.random() * 100)) %28 +1;
		return year + "" + (month > 10 ? month : "0" + month) +(day > 10 ? day : "0" + day); 
	}
	/**
	 * 生成派出所代码
	 * @return
	 */
	private static String randomGACoed(){
		int code = ((int)(Math.random() * 100)) % 50;
		return code > 10 ? code + "":"0" + code;
	}
	private static String randomGender(){
		return ((int)(Math.random() * 10) ) % 10 + "";
	}
}
